#ifndef TASKSESSION_H
#define TASKSESSION_H

#include <QObject>
#include <QTcpSocket>
#include <qnetworkreply.h>
#include <QByteArray>
#include <QTimer>
#include <http/httpserver.h>
#include <QProcess>
#include <QThread>
#include "echarts/jecharts.h"
#include "Temperature/tempmanager.h"
#include "Temperature/temptopdf.h"

class HttpServer;

class TaskSession : public QObject
{
    Q_OBJECT
public:
    TaskSession(QTcpSocket* skt ,HttpServer *parent);
    void setSocket(QTcpSocket* skt);
    ~TaskSession();

private:
    enum TaskType{
        TASK_NONE,
        TASK_OTHERS,
        TASK_GET_RECORD,
        TASK_EXPORT_RECORD
    };
    QTcpSocket* taskSocket;
    JECharts* echarts;
    QThread* eThread;
    TempToPdf* tempToPdf;
    QThread* pThread;
    TempManager* tManager;
    QString recordName;
    QString curOpt;
    int taskProgress;//0-100
    TaskType taskType;


    void recvParams(QByteArray qba);
    QString strTrans(QString str);
    QString getParam(QString paramName, QStringList params);
    QByteArray getAllDev(QStringList devList);
    QByteArray SetDevParam(QString dev, QString name);
    void CreateDevRecord(QStringList devList, QString begin, QString end);
    QByteArray GetDevRecord();
    void ExportDevRecord(QStringList devList, QString begin, QString end);
    QByteArray CheckExportProgress();
    void writeData(QString opt, QByteArray qba);
    void writeData(QByteArray qba);
    void fastReturn(QString msg, int code);

signals:
    void sessionFinished();
    void updateDevInfo(QString dev);
    void newEchartsTask(QDate startDate, QDate endDate);
    void newPdfTask(QStringList devList, QDate beginDate, QDate endDate);

private slots:
    void readSessionData();
    void sessionFinishSlot();
//    void pdfCreateFinish();
    void updateTaskProgress(int progress);
public slots:

};

#endif // TASKSESSION_H
